import merge from "webpack-merge";
import { Configuration } from "webpack";
import { getWebPackCommonConfig } from "./webpack.common";

const commoneConfig = getWebPackCommonConfig("development");

// const targetUrl = 'http://npm-server:2203'

function getWebPackDevConfig(): Configuration {
  return merge(commoneConfig, {
    devServer: {
      client: {
        overlay: false,
      },
      // hot: "only",
      open: false, // 自动打开浏览器
      compress: true, // 开启gzip压缩
      historyApiFallback: true, //不跳转
      hot: true, // 开启热更新,
      port: 8000,
      headers: {
        "Access-Control-Allow-Origin": "*",
      },
      static: "public",
      // proxy: [
      //   {
      //     context: ["/api"],
      //     target: targetUrl, // 目标地址 --> 服务器地址
      //     changeOrigin: true, // 允许跨域
      //     ws: true, // 允许websocket代理
      //     secure: false,
      //     rewrite: (path: string) => path.replace(/^\/api/, 'api/')
      //   },
      //   {
      //     context: ['/mock'],
      //      target: 'http://192.168.100.221:3000', // 目标地址 --> 服务器地址
      //     changeOrigin: true, // 允许跨域
      //     secure: false,
      //   }
      // ]
    },
  });
}

const webpackConfig = getWebPackDevConfig();
console.log("webpack configure such as ....");
// console.log(webpackConfig);

module.exports = webpackConfig;
